VERSION 5.00 Begin VB.Form frmDecBin Caption = "Number Base Convertor - Decimal to Binary" ClientHeight = 3420 ClientLeft = 60 ClientTop = 630 ClientWidth = 6855 LinkTopic = "Form1" Picture = "DecBin.frx":0000 ScaleHeight = 3420 ScaleWidth = 6855 StartUpPosition = 2 'CenterScreen Begin VB.TextBox txthex2 Height = 285 Left = 2040 TabIndex = 15 Top = 3120 Visible = 0 'False Width = 375 End Begin VB.TextBox txthex1 Height = 285 Left = 1320 TabIndex = 14 Top = 3120 Visible = 0 'False Width = 375 End Begin VB.TextBox txtnum Height = 285 Left = 240 TabIndex = 13 Top = 3000 Visible = 0 'False Width = 735 End Begin VB.CommandButton Command2 Caption = "Convert" BeginProperty Font Name = "Times New Roman" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 3720 TabIndex = 3 Top = 2640 Width = 1215 End Begin VB.TextBox txtDec BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 405 Left = 2640 TabIndex = 1 Top = 2640 Width = 495 End Begin VB.CommandButton Command1 Caption = "Exit" BeginProperty Font Name = "Times New Roman" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 5400 TabIndex = 0 Top = 2640 Width = 855 End Begin VB.Label lblhex BackStyle = 0 'Transparent BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Left = 360 TabIndex = 16 Top = 2160 Width = 6255 End Begin VB.Label lblout BackStyle = 0 'Transparent BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Left = 360 TabIndex = 12 Top = 1800 Width = 6255 End Begin VB.Image bitty Height = 480 Index = 7 Left = 240 Picture = "DecBin.frx":4B146 Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 6 Left = 1080 Picture = "DecBin.frx":4B588 Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 5 Left = 1920 Picture = "DecBin.frx":4B9CA Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 4 Left = 2760 Picture = "DecBin.frx":4BE0C Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 3 Left = 3600 Picture = "DecBin.frx":4C24E Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 2 Left = 4440 Picture = "DecBin.frx":4C690 Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 1 Left = 5280 Picture = "DecBin.frx":4CAD2 Top = 960 Width = 480 End Begin VB.Image bitty Height = 480 Index = 0 Left = 6120 Picture = "DecBin.frx":4CF14 Top = 960 Width = 480 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "1" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 7 Left = 6240 TabIndex = 11 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "2" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 6 Left = 5400 TabIndex = 10 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "4" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 5 Left = 4560 TabIndex = 9 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "8" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 4 Left = 3720 TabIndex = 8 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "16" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 3 Left = 2880 TabIndex = 7 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "32" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 2 Left = 2040 TabIndex = 6 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "64" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 1 Left = 1200 TabIndex = 5 Top = 600 Width = 375 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "128" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H000000FF& Height = 255 Index = 0 Left = 360 TabIndex = 4 Top = 600 Width = 375 End Begin VB.Label Label1 BackStyle = 0 'Transparent Caption = "Enter Decimal Number" BeginProperty Font Name = "Tahoma" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 360 TabIndex = 2 Top = 2760 Width = 2175 End Begin VB.Menu mnuHelp Caption = "&Help" Begin VB.Menu mnuTopics Caption = "Topics" End End Begin VB.Menu mnuAbout Caption = "&About" Begin VB.Menu mnuAboutNum Caption = "About Number Convertor" End End Attribute VB_Name = "frmDecBin" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Const light_off As String = ("c:\program files\devstudio\vb\graphics\icons\misc\lightoff.ico") Const light_on As String = ("c:\program files\devstudio\vb\graphics\icons\misc\lighton.ico") Private Sub Command1_Click() End Sub Private Sub Command2_Click() 'convert dec to bin Dim bit, dec, num As Single If txtDec.Text = "" Then txtDec.SetFocus Exit Sub End If dec = Val(txtDec.Text) txtnum.Text = dec txtDec.Text = "" lblout.Caption = "The above is the binary equivilant of the decimal number " & dec txtDec.SetFocus 'if number enter is higher than 255 then prompt for new number If dec > 255 Then MsgBox ("Enter a decimal number between 1 and 255 only !"), vbOKOnly txtDec.Text = "" txtDec.SetFocus Exit Sub End If 'reset lightbulbs to off For bit = 0 To 7 bitty(bit).Picture = LoadPicture("C:\program files\devstudio\vb\graphics\icons\misc\lightoff.ico") Next bit num = dec 'if number entered is one then light bit0 bulb and exit If num = 1 Then bitty(0).Picture = LoadPicture("C:\program files\devstudio\vb\graphics\icons\misc\lighton.ico") bitty(0).Tag = "On" Exit Sub ' End If 'create loop to use with arrays For bit = 0 To 7 'divide number by 2 num = num / 2 'if the nearest whole number/2 is more or less than the number/2 then turn that bit on If Int(num) <> num Then bitty(bit).Picture = LoadPicture("C:\program files\devstudio\vb\graphics\icons\misc\lighton.ico") bitty(bit).Tag = "On" End If 'check for even/odd numbers and adjust to make note of carry If Int(num) < num Then num = Int(num) ElseIf Int(num) > num Then num = Int(num) - 1 End If 'if num/2 is 1 then light next bit along If num = 1 Then bit = bit + 1 bitty(bit).Picture = LoadPicture("C:\program files\devstudio\vb\graphics\icons\misc\lighton.ico") bitty(bit).Tag = "On" Exit Sub ' End If Next bit Call hexconvert(num) End Sub Private Sub bitty_Click(Index As Integer) 'convert bin to dec Dim hex1, hex2 As Variant hex1 = Val(txthex1.Text) hex2 = Val(txthex2.Text) num = Val(txtnum.Text) If bitty(Index).Tag = "Off" Then bitty(Index).Picture = LoadPicture(light_on) bitty(Index).Tag = "On" If Index = 0 Then num = num + 1 hex1 = hex1 + 1 ElseIf Index = 1 Then num = num + 2 hex1 = hex1 + 2 ElseIf Index = 2 Then num = num + 4 hex1 = hex1 + 4 ElseIf Index = 3 Then num = num + 8 hex1 = hex1 + 8 ElseIf Index = 4 Then num = num + 16 hex2 = hex2 + 1 ElseIf Index = 5 Then num = num + 32 hex2 = hex2 + 2 ElseIf Index = 6 Then num = num + 64 hex2 = hex2 + 4 ElseIf Index = 7 Then num = num + 128 hex2 = hex2 + 8 End If txtDec.SetFocus bitty(Index).Picture = LoadPicture(light_off) bitty(Index).Tag = "Off" If Index = 0 Then num = num - 1 hex1 = hex1 - 1 ElseIf Index = 1 Then num = num - 2 hex1 = hex1 - 2 ElseIf Index = 2 Then num = num - 4 hex1 = hex1 - 4 ElseIf Index = 3 Then num = num - 8 hex1 = hex1 - 8 ElseIf Index = 4 Then num = num - 16 hex2 = hex2 - 1 ElseIf Index = 5 Then num = num - 32 hex2 = hex2 - 2 ElseIf Index = 6 Then num = num - 64 hex2 = hex2 - 4 ElseIf Index = 7 Then num = num - 128 hex2 = hex2 - 8 End If End If txtnum.Text = num txthex1.Text = hex1 txthex2.Text = hex2 txtDec.SetFocus Call hexconvert(num) End Sub Sub hexconvert(ByVal num As Single) ' convert to hex Dim hex1, hex2 As Variant hex1 = Val(txthex1.Text) hex2 = Val(txthex2.Text) If hex1 > 9 Then If hex1 = 10 Then hex1 = "a" ElseIf hex1 = 11 Then hex1 = "b" ElseIf hex1 = 12 Then hex1 = "c" ElseIf hex1 = 13 Then hex1 = "d" ElseIf hex1 = 14 Then hex1 = "e" ElseIf hex1 = 15 Then hex1 = "f" Else End If End If If hex2 > 9 Then If hex2 = 10 Then hex2 = "a" ElseIf hex2 = 11 Then hex2 = "b" ElseIf hex2 = 12 Then hex2 = "c" ElseIf hex2 = 13 Then hex2 = "d" ElseIf hex2 = 14 Then hex2 = "e" ElseIf hex2 = 15 Then hex2 = "f" Else End If End If lblout.Caption = ("The above is the binary equivilant of the decimal number ") & num lblhex.Caption = ("The Hex equivalent is ") & UCase(hex2) & UCase(hex1) End Sub Private Sub Form_Load() Dim counter For counter = 0 To 7 bitty(counter).Picture = LoadPicture(light_off) bitty(counter).Tag = "Off" Next counter Dim num As Single frmDecBin.Show txtDec.SetFocus End Sub Private Sub mnuAboutNum_Click() Dim Msg, Style, Title Msg = "Coding by Graham Pollitt 15/6/99" Style = vbOKOnly Title = "Number Conversion Utility" Response = MsgBox(Msg, Style, Title) End Sub